﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.Exceptions;
using Autodesk.Revit.UI;
using YArchitech.HVAC;
using YArchitech.LIB;
using YArchitech.MEP;
using YArchitech.Revit;
using YArchitech.Revit.RevitExtension;

namespace YArchitech.Plumbing
{
	[Transaction(TransactionMode.Manual)]
	[Regeneration(RegenerationOption.Manual)]
	public class RefrigerantPipeCreate : HYNoTranExternalCommand
	{
		[DllImport("user32.dll", EntryPoint = "SendMessageA")]
		public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);

		public override void FilterProcess()
		{
			base.FilterProcess();
		}

		public override Result HYExecute()
		{
			if (RefrigerantPipeCreate.hWndRevit == null)
			{
				RefrigerantPipeCreate.hWndRevit = new YJKWindowHandle(Process.GetCurrentProcess().MainWindowHandle);
			}
			FormRefrigerantPipeCreate formRefrigerantPipeCreate = new FormRefrigerantPipeCreate(base.Doc);
			formRefrigerantPipeCreate.Show(RefrigerantPipeCreate.hWndRevit);
			int wMsg = 7;
			RefrigerantPipeCreate.SendMessage(RefrigerantPipeCreate.hWndRevit.Handle, wMsg, IntPtr.Zero, IntPtr.Zero);
			HYPipeConnect myPipeConnect = new HYPipeConnect();
			Transaction transaction = null;
			Result result;
			for (;;)
			{
				try
				{
					FormMultiLinePipeSetting.IsOpenTran = false;
					XYZ xyz = base.UiDoc.Selection.PickPoint("请选择绘制冷媒管所基于线的起点...");
					XYZ xyz2 = null;
					if (xyz != null)
					{
						FormMultiLinePipeSetting.IsOpenTran = true;
						Pipe pipe = null;
						Pipe pipe2 = null;
						Pipe pipe3 = null;
						Pipe pipe4 = null;
						Pipe pipe5 = null;
						Pipe pipe6 = null;
						for (;;)
						{
							transaction = new Transaction(base.Doc, "绘制冷媒管");
							transaction.Start();
							try
							{
								ThwartwiseCreate thwartwiseCreate = new ThwartwiseCreate();
								bool gasLiquidIntegration = formRefrigerantPipeCreate.GasLiquidIntegration;
								List<double> list = formRefrigerantPipeCreate.Getoffset();
								List<double> level = formRefrigerantPipeCreate.GetLevel();
								List<double> diameter = formRefrigerantPipeCreate.GetDiameter();
								if (list == null || level == null || diameter == null)
								{
									break;
								}
								using (RefrigerantPipeCreateJip refrigerantPipeCreateJip = new RefrigerantPipeCreateJip(base.UiDoc, gasLiquidIntegration, list, formRefrigerantPipeCreate))
								{
									refrigerantPipeCreateJip.StartPoint = xyz;
									refrigerantPipeCreateJip.DrawSize = true;
									Application.DoEvents();
									refrigerantPipeCreateJip.SetPromptState("", false, true);
									xyz2 = refrigerantPipeCreateJip.PickEndPoint(xyz, "请选择绘制冷媒管所基于线的终点...");
									refrigerantPipeCreateJip.Dispose();
								}
								if (xyz2 == null)
								{
									break;
								}
								if (!xyz2.IsAlmostEqualTo(xyz))
								{
									PipeType pipeType = this.TestPipeType();
									if (pipeType == null)
									{
										pipeType = new OperateSegmentFitting(base.Doc).CreatHYPipeTypeByName(this.pipeTypeName);
										this.ChangeFirstRuleFitting(pipeType);
									}
									list = formRefrigerantPipeCreate.Getoffset();
									level = formRefrigerantPipeCreate.GetLevel();
									diameter = formRefrigerantPipeCreate.GetDiameter();
									if (gasLiquidIntegration)
									{
										double levelOffset = level[0] + this.Get_Level(base.Doc).ProjectElevation * 304.8;
										double offset = list[0];
										PipingSystemType pipingSystemType = this.PipingSystemTypeCreate(0, base.Doc);
										double paraDiameter = 50.8;
										XYZ newXYZDeriction = YJKRevitTools.getNewXYZDeriction(xyz, xyz2);
										HYCreatePipeHelper hycreatePipeHelper = new HYCreatePipeHelper();
										if (newXYZDeriction != null)
										{
											pipe2 = hycreatePipeHelper.DrawThwartwisePipe(base.Doc, offset, levelOffset, xyz, xyz2, pipeType, paraDiameter, pipingSystemType, 0.0, newXYZDeriction);
										}
										this.CreateParamPipe();
										this.SetRefrigerantPipeAttribute(pipe2, diameter);
										Line pipeline = YJKLineEx.YJKGetBound(xyz, xyz2);
										XYZ newParallelPipeXYZ = hycreatePipeHelper.getNewParallelPipeXYZ(xyz, pipeline, offset, newXYZDeriction);
										XYZ start = xyz;
										xyz = xyz2;
										xyz2 = null;
										if (pipe != null && pipe.IsValidObject && pipe2 != null)
										{
											Curve curve = (pipe.Location as LocationCurve).Curve;
											Curve curve2 = (pipe2.Location as LocationCurve).Curve;
											YJKLine hyline = new YJKLine(curve.GetEndPoint(0), curve.GetEndPoint(1));
											YJKLine hyline2 = new YJKLine(curve2.GetEndPoint(0), curve2.GetEndPoint(1));
											if (!hyline.IsLineOnLine(hyline2.Line) && !hyline.IsXYParallel(hyline2.Line))
											{
												List<Pipe> list2 = thwartwiseCreate.ExtendPipe(new List<Pipe>
												{
													pipe,
													pipe2
												}, start);
												if (list2 != null)
												{
													XYZ xyz3 = hyline.IntersectionPoint(hyline2.Line);
													int num = 1;
													int num2 = 1;
													if (xyz3 != null)
													{
														num = (hyline.EndPoint.IsAlmostEqualTo(xyz3, 0.001) ? 1 : -1);
														num2 = (hyline2.StartPoint.IsAlmostEqualTo(xyz3, 0.001) ? 1 : -1);
													}
													XYZ xyz4 = (hyline.EndPoint - hyline.StartPoint).Normalize() * (double)num;
													XYZ xyz5 = (hyline2.EndPoint - hyline2.StartPoint).Normalize() * (double)num2;
													YJKPipeConnectorHelper hypipeConnectorHelper = new YJKPipeConnectorHelper();
													if ((Math.Abs(xyz4.X) < 1E-06 && Math.Abs(xyz5.Y) < 1E-06) || (Math.Abs(xyz4.Y) < 1E-06 && Math.Abs(xyz5.X) < 1E-06))
													{
														if (!thwartwiseCreate.NewElbowFitting(list2, true))
														{
															MessageBox.Show("没有可以使用的族配置，请检查Revit的族配置", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
															transaction.RollBack();
															break;
														}
													}
													else if (xyz4.AngleTo(xyz5) * 180.0 / Math.PI <= 90.0)
													{
														if (!thwartwiseCreate.NewElbowFitting(list2, true))
														{
															MessageBox.Show("没有可以使用的族配置，请检查Revit的族配置", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
															transaction.RollBack();
															break;
														}
													}
													else
													{
														hypipeConnectorHelper.connect45Elbow(pipe, thwartwiseCreate.getxyz(pipe), pipe2, thwartwiseCreate.getxyz(pipe2), base.Doc);
													}
												}
											}
										}
										pipe = pipe2;
										List<Pipe> pickPipe = thwartwiseCreate.GetPickPipe(newParallelPipeXYZ, 0.032808398950131233, base.Doc);
										SubTransaction subTransaction = new SubTransaction(base.Doc);
										subTransaction.Start();
										try
										{
											this.ConnectPipes(pickPipe, ref pipe2, myPipeConnect, newParallelPipeXYZ);
											subTransaction.Commit();
											goto IL_6CB;
										}
										catch (Exception)
										{
											subTransaction.RollBack();
											goto IL_6CB;
										}
									}
									List<Pipe> rectangleAreaPipes = this.GetRectangleAreaPipes(xyz, (Math.Abs(list[0] - list[1]) + 5.0) / 304.8);
									for (int i = 0; i < 2; i++)
									{
										double levelOffset2 = level[i] + this.Get_Level(base.Doc).ProjectElevation * 304.8;
										double offset2 = list[i];
										PipingSystemType pipingSystemType2 = this.PipingSystemTypeCreate(i + 1, base.Doc);
										double paraDiameter2 = diameter[i];
										XYZ newXYZDeriction2 = YJKRevitTools.getNewXYZDeriction(xyz, xyz2);
										HYCreatePipeHelper hycreatePipeHelper2 = new HYCreatePipeHelper();
										if (newXYZDeriction2 != null)
										{
											if (i == 0)
											{
												pipe3 = hycreatePipeHelper2.DrawThwartwisePipe(base.Doc, offset2, levelOffset2, xyz, xyz2, pipeType, paraDiameter2, pipingSystemType2, 0.0, newXYZDeriction2);
											}
											else
											{
												pipe4 = hycreatePipeHelper2.DrawThwartwisePipe(base.Doc, offset2, levelOffset2, xyz, xyz2, pipeType, paraDiameter2, pipingSystemType2, 0.0, newXYZDeriction2);
											}
										}
									}
									XYZ point = xyz;
									xyz = xyz2;
									xyz2 = null;
									if (pipe5 != null && pipe5.IsValidObject && pipe3 != null && pipe6 != null && pipe6.IsValidObject && pipe4 != null)
									{
										List<Pipe> list3 = new List<Pipe>();
										list3.Add(pipe5);
										list3.Add(pipe3);
										this.ConnectPipes(list3, myPipeConnect, point);
										list3.Clear();
										list3.Add(pipe6);
										list3.Add(pipe4);
										this.ConnectPipes(list3, myPipeConnect, point);
									}
									else if (rectangleAreaPipes.Count == 2)
									{
										this.GasLiquidSeparatePipeConn(rectangleAreaPipes, pipe3, pipe4, myPipeConnect, point);
									}
									pipe5 = pipe3;
									pipe6 = pipe4;
								}
								IL_6CB:;
							}
							catch (Autodesk.Revit.Exceptions.OperationCanceledException)
							{
								pipe5 = null;
								pipe6 = null;
								transaction.RollBack();
								break;
							}
							base.Doc.Regenerate();
							transaction.Commit();
						}
						continue;
					}
					formRefrigerantPipeCreate.Close();
					result = Autodesk.Revit.UI.Result.Succeeded;
				}
				catch (Autodesk.Revit.Exceptions.OperationCanceledException)
				{
					formRefrigerantPipeCreate.Close();
					result = Autodesk.Revit.UI.Result.Succeeded;
				}
				catch (Exception)
				{
					this.EndTransation(transaction, false);
					formRefrigerantPipeCreate.Close();
					result = Autodesk.Revit.UI.Result.Succeeded;
				}
				finally
				{
					this.EndTransation(transaction, true);
				}
				break;
			}
			return result;
		}

		private void EndTransation(Transaction tran, bool beSure)
		{
			if (tran != null)
			{
				TransactionStatus status = tran.GetStatus();
				if ((int)status == 1)
				{
					if (beSure)
					{
						tran.Commit();
						return;
					}
					tran.RollBack();
					return;
				}
				else if ((int)status == 5)
				{
					tran.RollBack();
				}
			}
		}

		private List<Pipe> GetRectangleAreaPipes(XYZ point, double size)
		{
			XYZ point2 = new XYZ(point.X + size, point.Y + size, point.Z);
			XYZ point3 = new XYZ(point.X - size, point.Y - size, point.Z);
			List<Pipe> list = new List<Pipe>();
			BoundingBoxIntersectsFilter boundingBoxIntersectsFilter = new BoundingBoxIntersectsFilter(RevitAPIUIOperate.CreatOutLine(RevitAPIUIOperate.GetViewRange2(base.Doc.ActiveView, false), point2, point3));
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(base.Doc);
			filteredElementCollector.OfClass(typeof(Pipe)).OfCategory(BuiltInCategory.OST_PipeCurves).WherePasses(boundingBoxIntersectsFilter);
			foreach (Element element in filteredElementCollector)
			{
				Pipe pipe = (Pipe)element;
				if (pipe.GetParameter("系统类型").AsValueString() == "气管" || pipe.GetParameter("系统类型").AsValueString() == "液管")
				{
					list.Add(pipe);
				}
			}
			return list;
		}

		public bool FilterPipeType(Pipe pipe1, Pipe pipe2)
		{
			return pipe1.GetParameter("系统类型").AsValueString() == pipe2.GetParameter("系统类型").AsValueString();
		}

		private void GasLiquidSeparatePipeConn(List<Pipe> listPipe, Pipe newpipe1, Pipe newpipe2, HYPipeConnect myPipeConnect, XYZ point)
		{
			if (listPipe[0].GetParameter("系统类型").AsValueString() == "气管" && listPipe[1].GetParameter("系统类型").AsValueString() == "液管")
			{
				List<Pipe> list = new List<Pipe>();
				list.Add(listPipe[0]);
				list.Add(newpipe1);
				this.ConnectPipes(list, myPipeConnect, point);
				list.Clear();
				list.Add(listPipe[1]);
				list.Add(newpipe2);
				this.ConnectPipes(list, myPipeConnect, point);
				return;
			}
			if (listPipe[1].GetParameter("系统类型").AsValueString() == "气管" && listPipe[0].GetParameter("系统类型").AsValueString() == "液管")
			{
				List<Pipe> list2 = new List<Pipe>();
				list2.Add(listPipe[1]);
				list2.Add(newpipe1);
				this.ConnectPipes(list2, myPipeConnect, point);
				list2.Clear();
				list2.Add(listPipe[0]);
				list2.Add(newpipe2);
				this.ConnectPipes(list2, myPipeConnect, point);
			}
		}

		private bool ConnectPipes(List<Pipe> GlobalPipe, ref Pipe pipe, HYPipeConnect myPipeConnect, XYZ point)
		{
			ThwartwiseCreate thwartwiseCreate = new ThwartwiseCreate();
			if (GlobalPipe.Count<Pipe>() != 2)
			{
				return false;
			}
			bool result = true;
			IList<Pipe> list = new List<Pipe>();
			Pipe pipe2 = (GlobalPipe[0].Id == pipe.Id) ? GlobalPipe[1] : GlobalPipe[0];
			if (!this.FilterPipeType(pipe2, pipe))
			{
				return false;
			}
			list.Add(pipe2);
			list.Add(pipe);
			new YJKPiping<Pipe>(pipe2);
			int num = thwartwiseCreate.CheckPipePosition(pipe2, pipe);
			if (num <= 12)
			{
				if (num != 10)
				{
					if (num == 12)
					{
						thwartwiseCreate.SamePlaneElbowConnPipes(list);
					}
				}
				else
				{
					thwartwiseCreate.SameLineConnPipes(list, myPipeConnect);
				}
			}
			else if (num != 22)
			{
				if (num == 23)
				{
					this.AntaraficialTeeConnPipes(list, myPipeConnect, point);
				}
			}
			else
			{
				thwartwiseCreate.AntarafacialElbowConnPipes(list, myPipeConnect, point);
			}
			if (pipe != null && !pipe.IsValidObject)
			{
				pipe = pipe2;
			}
			return result;
		}

		public void AntaraficialTeeConnPipes(IList<Pipe> pipes, HYPipeConnect myPipeConnect, XYZ point)
		{
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(pipes[0]);
			YJKPiping<Pipe> hypiping2 = new YJKPiping<Pipe>(pipes[1]);
			Line line = Line.CreateBound(hypiping.StartConnector.Origin, hypiping.EndConnector.Origin);
			Line line2 = Line.CreateBound(hypiping2.StartConnector.Origin, hypiping2.EndConnector.Origin);
			YJKLine xyproject = hypiping.GetXYProject();
			YJKLine xyproject2 = hypiping2.GetXYProject();
			xyproject2.MakeUnBound();
			XYZ xyz = xyproject.IntersectionPoint(xyproject2.Line);
			XYZ xyz2 = new XYZ(0.0, 0.0, 0.0);
			if (xyz != null && !xyz.IsAlmostEqualTo(xyz2, 0.0001))
			{
				XYZ end = new XYZ(xyz.X, xyz.Y, xyz.Z + 10.0);
				YJKLine hyline = new YJKLine(xyz, end);
				hyline.MakeUnBound();
				line.MakeUnbound();
				line2.MakeUnbound();
				XYZ xyz3 = hyline.IntersectionPoint(line);
				XYZ xyz4 = hyline.IntersectionPoint(line2);
				if (xyz3 != null && xyz4 != null && xyz3.DistanceTo(xyz4) > hypiping2.GetDiameter() * 3.0)
				{
					Pipe item = YJKRevitTools.NewPipe(hypiping2.Piping, xyz3, xyz4);
					IList<Pipe> list = new List<Pipe>();
					list.Add(item);
					list.Add(hypiping2.Piping);
					myPipeConnect.NewElbowFitting(list, true);
					list.Clear();
					list.Add(item);
					list.Add(hypiping.Piping);
					list.Add(hypiping.Piping);
					return;
				}
			}
			else if (xyproject2.GetDistance(xyproject.StartPoint) < 0.016404199475065617)
			{
				Connector closeConnector = hypiping2.GetCloseConnector(point, false);
				XYZ project = hypiping.GetProject(point);
				if (project.DistanceTo(closeConnector.Origin) > hypiping2.GetDiameter() * 3.0)
				{
					Pipe item2 = YJKRevitTools.NewPipe(hypiping2.Piping, closeConnector.Origin, project);
					IList<Pipe> list2 = new List<Pipe>();
					list2.Add(item2);
					list2.Add(hypiping2.Piping);
					myPipeConnect.NewElbowFitting(list2, true);
					list2.Clear();
					list2.Add(item2);
					list2.Add(hypiping.Piping);
					list2.Add(hypiping.Piping);
				}
			}
		}

		private void ConnectPipes(List<Pipe> pipes, HYPipeConnect myPipeConnect, XYZ point)
		{
			try
			{
				if (this.FilterPipeType(pipes[0], pipes[1]))
				{
					ThwartwiseCreate thwartwiseCreate = new ThwartwiseCreate();
					int num = this.CheckPipePosition(pipes[0], pipes[1], point);
					if (num != 10)
					{
						if (num != 12)
						{
							if (num == 22)
							{
								thwartwiseCreate.AntarafacialElbowConnPipes(pipes, myPipeConnect, point);
							}
						}
						else
						{
							thwartwiseCreate.SamePlaneElbowConnPipes(pipes);
						}
					}
					else
					{
						thwartwiseCreate.SameLineConnPipes(pipes, myPipeConnect);
					}
				}
			}
			catch (Exception)
			{
			}
		}

		private int CheckPipePosition(Pipe pipe1, Pipe pipe2, XYZ point)
		{
			ThwartwiseCreate thwartwiseCreate = new ThwartwiseCreate();
			int result = 0;
			double diameter = pipe1.Diameter;
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(pipe1);
			YJKPiping<Pipe> hypiping2 = new YJKPiping<Pipe>(pipe2);
			Curve curve = (pipe1.Location as LocationCurve).Curve;
			Line otherLine = (pipe2.Location as LocationCurve).Curve as Line;
			YJKLine hyline = new YJKLine(hypiping.StartConnector.Origin, hypiping.EndConnector.Origin);
			YJKLine hyline2 = new YJKLine(hypiping2.StartConnector.Origin, hypiping2.EndConnector.Origin);
			Connector closeConnector = hypiping.GetCloseConnector(point, false);
			XYZ project = hypiping.GetProject(point);
			if (thwartwiseCreate.IsLineOnLine(hyline, hyline2, 0.03))
			{
				result = 10;
			}
			else if (hyline.GetDPLineDistance(otherLine) > diameter * 3.0 || (hyline.IsXYParallel(otherLine) && hyline.GetDistance(hyline2.StartPoint) > diameter * 3.0))
			{
				if (closeConnector.Origin.DistanceTo(project) < 0.65616797900262469)
				{
					result = 22;
				}
			}
			else if (hyline.IntersectionPoint(otherLine, 0.03) != null && closeConnector.Origin.DistanceTo(project) < 0.65616797900262469)
			{
				result = 12;
			}
			return result;
		}

		public Level Get_Level(Autodesk.Revit.DB.Document document)
		{
			Level level = document.ActiveView.GenLevel;
			if (level == null)
			{
				FilteredElementCollector filteredElementCollector = new FilteredElementCollector(base.Doc);
				filteredElementCollector.OfClass(typeof(Level)).OfCategory(BuiltInCategory.OST_Levels);
				double num = 10000.0;
				foreach (Element element in filteredElementCollector)
				{
					Level level2 = (Level)element;
					if (level2.ProjectElevation < num)
					{
						level = level2;
						num = level2.ProjectElevation;
					}
				}
			}
			return level;
		}

		private PipeType TestPipeType()
		{
			foreach (Element element in YJKElementFilter.GetElementByClass(typeof(PipeType), base.Doc))
			{
				if (element.Name == this.pipeTypeName)
				{
					return element as PipeType;
				}
			}
			return null;
		}

		public PipingSystemType Get_PipingSystemType(Autodesk.Revit.DB.Document document, string pipingSystemTypeName)
		{
			ICollection<Element> elementByClass = YJKElementFilter.GetElementByClass(typeof(PipingSystemType), document);
			return this.GetElementSameName(elementByClass, pipingSystemTypeName) as PipingSystemType;
		}

		private Element GetElementSameName(ICollection<Element> collection, string elemName)
		{
			Element result = null;
			foreach (Element element in collection)
			{
				if (element != null && element.Name == elemName)
				{
					result = element;
				}
			}
			return result;
		}

		public PipingSystemType PipingSystemTypeCreate(int i, Autodesk.Revit.DB.Document doc)
		{
			List<List<string>> multiLinePipeSetting = new ClassRefrigerantPipeCreateInfo().GetMultiLinePipeSetting();
			string text = multiLinePipeSetting[i][0];
			string text2 = multiLinePipeSetting[i][1];
			string text3 = multiLinePipeSetting[i][2];
			string text4 = multiLinePipeSetting[i][3];
			string text5 = multiLinePipeSetting[i][4];
			string chName = multiLinePipeSetting[i][5];
			PipingSystemType pipingSystemType = this.Get_PipingSystemType(doc, text);
			if (pipingSystemType == null)
			{
				MEPSystemClassification mepsystemClassification = (MEPSystemClassification)Enum.Parse(typeof(MEPSystemClassification), AssistSystemType.GetPipeSystemTypeUS(chName), true);
				pipingSystemType = PipingSystemType.Create(doc, mepsystemClassification, text);
			}
			pipingSystemType.get_Parameter(BuiltInParameter.RBS_SYSTEM_ABBREVIATION_PARAM).Set(text2);
			if (text3 != "默认")
			{
				pipingSystemType.LineColor = new Autodesk.Revit.DB.Color((byte)int.Parse(text3.Split(new char[]
				{
					' '
				}).ElementAt(1)), (byte)int.Parse(text3.Split(new char[]
				{
					' '
				}).ElementAt(2)), (byte)int.Parse(text3.Split(new char[]
				{
					' '
				}).ElementAt(3)));
			}
			if (text4 != "默认")
			{
				pipingSystemType.LinePatternId = LinePatternElement.GetLinePatternElementByName(doc, text4).Id;
			}
			if (text5 != "默认")
			{
				pipingSystemType.LineWeight = int.Parse(text5);
			}
			return pipingSystemType;
		}

		private void ChangeFirstRuleFitting(PipeType pipeType)
		{
			string text = "";
			for (int i = 0; i < 6; i++)
			{
				UnifiedModified.ClearSegmentFitting(pipeType, i);
			}
			UnifiedModified.ClearSegmentFitting(pipeType, 10);
			PipeSegment pipeSegment = this.CreatePipeSegment();
			UnifiedModified.SetSegmentFitting(pipeType, 0, pipeSegment.Id, "管段");
			FamilySymbol familySymbol = YJKRevitTools.GetFamilySymbol("弯头_焊接_铜管", base.Doc);
			if (familySymbol == null)
			{
				familySymbol = YJKRevitTools.GetFamilySymbolByName("Fitting", "弯头_焊接_铜管", base.Doc, ref text);
			}
			UnifiedModified.SetSegmentFitting(pipeType, 1, familySymbol.Id, "弯头_焊接_铜管");
			FamilySymbol familySymbol2 = YJKRevitTools.GetFamilySymbol("等径三通_焊接_铜管", base.Doc);
			if (familySymbol2 == null)
			{
				familySymbol2 = YJKRevitTools.GetFamilySymbolByName("Fitting", "等径三通_焊接_铜管", base.Doc, ref text);
			}
			UnifiedModified.SetSegmentFitting(pipeType, 2, familySymbol2.Id, "等径三通_焊接_铜管");
			FamilySymbol familySymbol3 = YJKRevitTools.GetFamilySymbol("变径三通_焊接_铜管", base.Doc);
			if (familySymbol3 == null)
			{
				familySymbol3 = YJKRevitTools.GetFamilySymbolByName("Fitting", "变径三通_焊接_铜管", base.Doc, ref text);
			}
			UnifiedModified.SetSegmentFitting(pipeType, 2, familySymbol3.Id, "变径三通_焊接_铜管");
			FamilySymbol familySymbol4 = YJKRevitTools.GetFamilySymbol("四通_焊接_铜管", base.Doc);
			if (familySymbol4 == null)
			{
				familySymbol4 = YJKRevitTools.GetFamilySymbolByName("Fitting", "四通_焊接_铜管", base.Doc, ref text);
			}
			UnifiedModified.SetSegmentFitting(pipeType, 3, familySymbol4.Id, "四通_焊接_铜管");
			FamilySymbol familySymbol5 = YJKRevitTools.GetFamilySymbol("变径_焊接_铜管", base.Doc);
			if (familySymbol5 == null)
			{
				familySymbol5 = YJKRevitTools.GetFamilySymbolByName("Fitting", "变径_焊接_铜管", base.Doc, ref text);
			}
			UnifiedModified.SetSegmentFitting(pipeType, 4, familySymbol5.Id, "变径_焊接_铜管");
			FamilySymbol familySymbol6 = YJKRevitTools.GetFamilySymbol("管帽-焊接", base.Doc);
			if (familySymbol6 == null)
			{
				familySymbol6 = YJKRevitTools.GetFamilySymbolByName("Fitting", "管帽-焊接", base.Doc, ref text);
			}
			UnifiedModified.SetSegmentFitting(pipeType, 10, familySymbol6.Id, "管帽-焊接");
		}

		private PipeSegment CreatePipeSegment()
		{
			OperateSegmentFitting operateSegmentFitting = new OperateSegmentFitting(base.Doc);
			HYMaterial hymaterial = new HYMaterial();
			hymaterial.Name = "铜";
			hymaterial.Roughness = 0.01;
			hymaterial.TubeType = 1;
			hymaterial.Segment = "铜";
			hymaterial.Schedule = "焊接";
			HYPipeSpecifications hypipeSpecifications = new HYPipeSpecifications();
			List<List<string>> pipeStorage = new ClassRefrigerantPipeCreateInfo().GetPipeStorage();
			new List<HYPipeSpecification>();
			int num = 0;
			foreach (List<string> list in pipeStorage)
			{
				hypipeSpecifications.Add(new HYPipeSpecification
				{
					DN = num,
					DN2 = list[0].ToDouble(0.0),
					Diameter = list[2].ToDouble(0.0),
					Thickness = list[2].ToDouble(0.0) - list[1].ToDouble(0.0)
				});
				num++;
			}
			hymaterial.Specifications = hypipeSpecifications;
			PipeSegment pipeSegment = operateSegmentFitting.CreatHYPipeSegment2(hymaterial);
			pipeSegment.Roughness = hymaterial.Roughness / 304.8;
			return pipeSegment;
		}

		private void CreateParamPipe()
		{
			string pathName = Path.Combine(Product.DataLocation, "HYShared Parameters.txt");
			string gropeName = "管道参数";
			List<string> list = new List<string>();
			list.Add("气管管径");
			list.Add("液管管径");
			YJKRevitTools.SetInstanceParameter(base.UiApp, pathName, gropeName, list, BuiltInCategory.OST_PipeCurves, false);
		}

		private void SetRefrigerantPipeAttribute(Pipe pipe, List<double> diameters)
		{
			if (diameters[0] > 0.0 && pipe.GetParameter("气管管径") != null)
			{
				pipe.GetParameter("气管管径").Set(diameters[0] / 304.8);
			}
			if (diameters[1] > 0.0 && pipe.GetParameter("液管管径") != null)
			{
				pipe.GetParameter("液管管径").Set(diameters[1] / 304.8);
			}
		}

		private string pipeTypeName = "铜管-焊接";

		public static YJKWindowHandle hWndRevit;
	}
}
